(function($) {
	$.fn.loadButtons = function(buttons,settings) {
		$(this).empty();
		var ins = this;
		this.edit = function() {
			editMode();
		};
		this.create = function() {};
		this.save = function() {};
		
		this.newVersion = function() {
			if(typeof(newVerMode) == "function"){
				newVerMode();
			}
		}
		
		this.submit = function (event){			
			if(typeof(beforeSubmit) == "function"){
				beforeSubmit();
			}
			$("#mainForm").attr("action",event.data.url);
			$("#mainForm").submit();
		}

		
		
		this.afterSubmit = function() {};
		
		this._settings = $.extend(true,{
			'new':{'id':'createNewBtn','text':'New','icon':'icon142','hide':false,'url':'/new','event':this.create},
			'newVer':{'id':'createNewVerBtn','text':'New Ver','icon':'icon55','hide':false,'url':'#','callback':this.afterSubmit,'event':this.submit},
			'addGrp':{'id':'addGrpBtn','text':'Add Grp','icon':'icon137','hide':false,'url':'/addGrp','callback':this.afterSubmit,'event':this.submit},
			'abc':{'id':'abcBtn','text':'ABC','icon':'icon94','hide':true,'url':'/checkAbc','callback':this.afterSubmit,'event':this.submit},
			'cancel':{'id':'cancelBtn','text':'Cancel','icon':'icon35','hide':false,'url':'/cancel','callback':this.afterSubmit,'event':this.submit},
			'edit':{'id':'editBtn','text':'Edit','icon':'icon144','hide':false,'url':'#','callback':this.afterSubmit,'event':this.edit},
			'save':{'id':'saveBtn','text':'Save','icon':'icon67','hide':true,'url':'/save','callback':this.afterSubmit,'event':this.submit},
			'accept':{'id':'acceptBtn','text':'Accept','icon':'icon44','hide':false,'url':'/accept','callback':this.afterSubmit,'event':this.submit},			
			'decline':{'id':'declineBtn','text':'Decline','icon':'icon56','hide':false,'url':'/decline','callback':this.afterSubmit,'event':this.submit},
			'propose':{'id':'proposeBtn','text':'Propose','icon':'icon189','hide':false,'url':'/propose','callback':this.afterSubmit,'event':this.submit},
			'delete':{'id':'deleteBtn','text':'Delete','icon':'icon186','hide':false,'url':'/delete','callback':this.afterSubmit,'event':this.submit},
			'mail':{'id':'mailBtn','text':'Mail','icon':'icon125','hide':false,'url':'#','callback':this.afterSubmit,'event':this.submit}
		}, settings);
		
		this.createBtn = function(btn) {
			var icon_span = $("<span/>").addClass("icon").addClass(this._settings[btn]["icon"]);
			var text_span = $("<span/>").addClass("label").text(this._settings[btn]["text"]);
			var link = $("<a/>").attr("id", this._settings[btn]["id"]).attr("href","javascript:void(0);").addClass("button");
			//link.click(this._settings[btn]["event"]);
			link.bind('click',{url:this._settings[btn]["url"],callback:this._settings[btn]["callback"]},this._settings[btn]["event"]);
			link.append(icon_span).append(text_span);
			$(this).append(link);
			if(this._settings[btn]["hide"]){
				$(link).hide();
			}
		};

		for (i = 0; i < buttons.length; i++) {
			var btn = buttons[i];
			this.createBtn(btn);
		}
	};
})(jQuery);